package com.sorting;

/**
 * Created by nkrivko on 23.12.2014.
 */
//(n*n)/2 compares and n exchanges
public class SelectionSort implements Sort {

    @Override
    public void sort(char[] s) {
        int length = s.length;

        for (int i = 0; i < length; i++) {
            int min = i;
            for (int j = i + 1; j < length; j++) {
                if (s[j] < s[min]) {
                    min = j;
                }
                Util.exchange(s, i, min);
            }
        }
        System.out.print("Seletion sort: ");
        Util.show(s);
    }

}
